import axios, {AxiosRequestConfig, AxiosResponse} from 'axios'
import { ElLoading } from 'element-plus'
const service = axios.create({
    baseURL:"http://127.0.0.1:8081",
    // baseURL:"http://127.0.0.1:8081",
    timeout:5000
})
let loading:any
const startLoading = () => {
    interface Options {
        lock: boolean,
        text: string,
        background: string
    }
    const options:Options = {
        lock: true,
        text: "玩命加载中...",
        background: 'rgba(0,0,0,0.7)'
    }
    loading = ElLoading.service(options)
}
const endLoading = () => {
    loading.close();
}
//请求拦截 模拟
service.interceptors.request.use((config:AxiosRequestConfig) => {
    // 加载
    startLoading()
    //可以加token
    return config
})
//响应拦截
service.interceptors.response.use((response:AxiosResponse<any>) => {
    endLoading()
    return response
}, error => {
    //错误提醒
    return Promise.reject(error);
})
export default service;